/**
 * Created by vlean on 2018/10/11.
 */
const {client, xml, jid} = require('@xmpp/client')

const xmpp = client({
    service: '127.0.0.1',
    domain: '127.0.0.1',
    resource: '',
    username: 'username',
    password: 'password',
})

xmpp.on('error', err => {
    console.error('❌', err.toString())
})

xmpp.on('offline', () => {
    console.log('🛈', 'offline')
})

xmpp.on('online', async address => {
    console.log('🗸', 'online as', address.toString())

    // Sends a chat message to itself
    const message = xml(
        'message',
        {type: 'chat', to: address},
        xml('body', 'hello world')
    )
    xmpp.send(message)
})

xmpp.on('stanza', stanza => {
    console.log('⮈', stanza.toString())
xmpp.stop()
})

xmpp.start()
